//created by: Lim Yi Le
Ext.define("MajorProjectSenchaTouch.view.LibraryUpdatesModule.LibraryUpdatesDataview", {
    extend:'Ext.DataView',
    xtype: 'libraryupdatesdataview',
    id: 'libraryUpdatesDataview',
    requires:[
        'MajorProjectSenchaTouch.store.LibraryUpdates'
    ],
    
    config:{
        itemTpl: new Ext.XTemplate(
            '<tpl for=".">',
                '<div class="productBox">',
                    '<div class="productDate">',
                        '<div class="productDateText">{pubDate:date("j F Y")}</div>',
                    '</div>',
                    '<div class="productBody">',
                        '<h1><p align="right">{title}</p></h1>',
                        '<hr>',
                        '<h4>{summaryContent}</h4>',
                        '<tpl if="summary">',
                            '<div class="disclosureIcon">',
                            '<img id="disclosureIcon" src="sdk/resources/themes/images/default/pictos/code3.png">',
                            '</div>',
                        '</tpl>',
                    '</div>',
                '</div>',
            '</tpl>'    
        ),
        store: 'LibraryUpdates',
        listeners: {
            // handles event where a summarized library updates post is tapped
            itemtap: function(view, index, target, record, e){
                var isSummary = record.data.summary;
                // if it is a summarized post, retrieves selected post data and passes it to LibraryUpdates 
                // controller to open a page with the full content
                if(isSummary){
                    var title = record.data.title;
                    var fullContent = record.data.fullContent;
                    var pubDate = record.data.pubDate;
                    var luControl = MajorProjectSenchaTouch.app.getController('LibraryUpdates');
                    luControl.goFullviewPage(title, fullContent, pubDate);
                }
            }
        }
    }
});

